package com.gcb.controller.common;

import com.gcb.common.core.domain.AjaxResult;
import com.gcb.common.core.domain.R;
import com.gcb.common.core.domain.vo.CommonEnum;
import com.gcb.common.enums.*;
import com.gcb.common.utils.EnumUtils;
import com.gcb.common.utils.huawei.ObsUtils;
import com.gcb.common.utils.huawei.OcrUtils;
import com.gcb.common.utils.huawei.vo.BusinessLicenseResultVO;
import com.gcb.common.utils.huawei.vo.IdCardResultVO;
import com.gcb.service.IPortService;
import com.gcb.service.IRegionService;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 通用请求处理
 *
 * @author linying
 */
@RestController
@RequestMapping("/common")
public class CommonController {

    @Resource
    private IRegionService regionService;

    @Resource
    private IPortService portService;

    /**
     * 上传到OBS中
     */
    @PostMapping("/uploadObsFile")
    public AjaxResult uploadObsFile(@RequestParam("file") MultipartFile file) throws Exception {
        String url = ObsUtils.fileUpload(file);
        AjaxResult ajax = AjaxResult.success();
        Map<String, String> resultMap = new HashMap<>();
        resultMap.put("url", url);
        ajax.put("data", resultMap);
        return ajax;
    }

    /**
     * 身份证识别
     */
    @GetMapping("/idCardOcr")
    public AjaxResult idCardOcr(String fileUrl, String side) {
        IdCardResultVO idCardResultVO = OcrUtils.idCardOcrWithUrl(fileUrl, side);
        return AjaxResult.success(idCardResultVO);
    }

    /**
     * 营业执照识别
     */
    @GetMapping("/businessLicenseOcr")
    public AjaxResult businessLicenseOcr(String fileUrl) {
        BusinessLicenseResultVO businessLicenseResultVO = OcrUtils.businessLicenseOcrWithUrl(fileUrl);
        return AjaxResult.success(businessLicenseResultVO);
    }

    /**
     * 获取地区树
     * @param level 级别
     * @return
     */
    @GetMapping("/getRegionTree")
    public AjaxResult getRegionTree(Integer level) {
        if (level == null) {
            level = 3;
        }
        return AjaxResult.success(regionService.getRegionTree(level));
    }

    /**
     * 获取港口列表
     *
     * @return
     */
    @GetMapping("/getPortList")
    public AjaxResult getPortList() {
        return AjaxResult.success(portService.selectAll());
    }

    /**
     * 获取创建类型枚举
     *
     * @return
     */
    @GetMapping("/enum/createType")
    public R<List<CommonEnum>> getCreateTypeList() {
        return R.ok(EnumUtils.enumToList(CreateTypeEnum.class));
    }

    /**
     * 获取平台状态枚举
     * @return
     */
    @GetMapping("/enum/authStatus")
    public R<List<CommonEnum>> getPlatformStatusList() {
        return R.ok(EnumUtils.enumToList(AuthStatusEnum.class));
    }

    /**
     * 获取证书等级枚举
     * @return R
     */
    @GetMapping("/enum/credentialsLevel")
    public R<List<CommonEnum>> credentialsLevelTreeList() {
        return R.ok(EnumUtils.enumToList(CredentialsLevelEnum.class));
    }

    /**
     * 获取学历枚举
     * @return R
     */
    @GetMapping("/enum/education")
    public R<List<CommonEnum>> educationLevelTreeList() {
        return R.ok(EnumUtils.enumToList(EducationLevel.class));
    }

    /**
     * 获取职务资格枚举
     * @return R
     */
    @GetMapping("/enum/credentialsType")
    public R<List<CommonEnum>> credentialsTypeTreeList() {
        return R.ok(EnumUtils.enumToList(CredentialsTypeEnum.class));
    }

    /**
     * 207.船舶类型枚举下拉列表
     */
    @GetMapping("/enum/shipType")
    public R<List<CommonEnum>> shipTypeEnumList() {
        List<CommonEnum> treeList = EnumUtils.enumToList(ShipTypeEnum.class);
        return R.ok(treeList);
    }

    @GetMapping("/enum/sex")
    public R<List<CommonEnum>> sexEnumList(){
        return R.ok(EnumUtils.enumToList(SexTypeEnum.class));
    }

    @GetMapping("/enum/userTag")
    public R<List<CommonEnum>> userTagEnumList(){
        return R.ok(EnumUtils.enumToList(UserTagEnum.class));
    }

    @GetMapping("/enum/commonStatus")
    public R<List<CommonEnum>> commonStatusEnumList() {
        return R.ok(EnumUtils.enumToList(CommonStatusEnum.class));
    }
}
